﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Actuals.CoreDomain.Business;
using Actuals.Common;
using Actuals.Business;
using Actuals.CoreDomain.Data;
using Actuals.CoreDomain;

namespace Actuals
{
    public partial class ShowPartTimeDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IBusinessTeam businessTeam = new BusinessTeam();
                IList<ITeam> teams = businessTeam.GetTeams();
                ddlTeam.DataSource = teams;
                ddlTeam.DataTextField = "TeamDescription";
                ddlTeam.DataValueField = "TeamId";
                ddlTeam.DataBind();
            }
            else
            {
                if (Request.Form["__EVENTTARGET"] == "refresh")
                {
                    BindGridView();
                }
            }
        }

        protected void BindGridView()
        {
            int teamId = int.Parse(ddlTeam.SelectedValue);
            IBusinessPartTimeDetail businessPartTimeDetail = new BusinessPartTimeDetail();
            IList<IPartTimeDetails> partTimeDetails = businessPartTimeDetail.GetPartTimeDetailsForTeam(teamId);
            gvShowPartTimers.DataSource = partTimeDetails;
            gvShowPartTimers.DataBind();
        }



        protected void btnShowPartTimers_Click(object sender, EventArgs e)
        {
            BindGridView();
        }

        protected void gvShowPartTimers_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string releaseId;
            switch (e.CommandName)
            {
                case "EditPartTimer":
                    releaseId = e.CommandArgument.ToString();
                    ClientScript.RegisterStartupScript(this.GetType(), "ShowUpdateRelease", "ShowUpdateRelease('" + releaseId + "');", true);
                    break;
            }
        }

        protected void btnDeletePartTimer_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < gvShowPartTimers.Rows.Count; i++)
                {

                    CheckBox cb = (CheckBox)gvShowPartTimers.Rows[i].FindControl("chkShowPartTimer");
                    Label lbl = (Label)gvShowPartTimers.Rows[i].FindControl("lblPartTimeId");
                    if (cb.Checked)
                    {
                        string partTimeId = string.Empty;
                        if (lbl != null)
                        {
                            partTimeId = lbl.Text;
                            IBusinessPartTimeDetail businessPartTimeDetails = new BusinessPartTimeDetail();
                            businessPartTimeDetails.DeletePartTimeDetails(int.Parse(partTimeId.ToString()));                            
                        }
                    }
                  
                }
                lblMsg.Text = "Deleted";
                BindGridView();
               

            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;

            }
        }

        protected string getEmployeeName(object employeeId)
        {
            IBusinessEmployee businessEmployee = new BusinessEmployee();
            IEmployee employeeName = businessEmployee.GetEmployee(int.Parse(employeeId.ToString()));
            return employeeName.NickName;

        }


    }



}
